<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta charset="UTF-8">
    <th:block th:include="include :: header('修改分类编码')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-flcode-edit" th:object="${flcode}">
        <input name="flId" type="hidden" th:field="*{flId}" />
        <input id="treeId" name="parentId" type="hidden" th:field="*{parentId}" />
        <input type="hidden" id="parflCodecomplete" th:value="*{parflCodecomplete}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">上级分类编码：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" id="treeName" onclick="selectDeptTree()" readonly="true" th:field="*{parentName}">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">分类编码名称：</label>
            <div class="col-sm-8">
                <input class="form-control" autocomplete="off" type="text" name="flName" th:field="*{flName}" id="deptName" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">分类编码标识：</label>
            <div class="col-sm-8">
                <input class="form-control" autocomplete="off" type="text" name="flCode" id="flCode" th:field="*{flCode}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">完整分类编码标识：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" autocomplete="off" name="flCodecomplete" id="flCodecomplete" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">显示排序：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" autocomplete="off" name="orderNum" th:field="*{orderNum}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">类型：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('base_flcode_type')}">
                    <input type="radio" th:id="${dict.dictCode}" name="flType" th:value="${dict.dictValue}" th:field="*{flType}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">分类编码状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                    <input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea class="form-control" autocomplete="off" type="text" rows="3" name="remark" th:field="*{remark}"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var prefix = ctx + "base_";
    var fl_Codecomplete = [[${flcode.flCodecomplete}]];

    //校验
    $("#form-flcode-edit").validate({
        onkeyup: false,
        rules:{
            flName:{
                remote: {
                    url: prefix + "/checkflNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "flId": function() {
                            return $("#flId").val();
                        },
                        "parentId": function() {
                            return $("input[name='parentId']").val();
                        },
                        "flName": function() {
                            return $.common.trim($("#flName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            orderNum:{
                digits:true
            }
        },
        messages: {
            flName: {
                remote: "分类编码已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-flcode-edit').serialize());
        }
    }

    window.onload = function () {
        $("#flCodecomplete").attr('value',fl_Codecomplete);
    }

    //监听改变
    $("#flCode").on({
        focus:function(){
            if($("#parflCodecomplete").val()==''||$("#parflCodecomplete").val()==null){
                $("#flCodecomplete").attr('value',$("#flCode").val());
            }else{
                $("#flCodecomplete").attr('value',$("#parflCodecomplete").val()+"-"+$("#flCode").val());
            }
        },
        blur:function(){
            if($("#parflCodecomplete").val()==''||$("#parflCodecomplete").val()==null){
                $("#flCodecomplete").attr('value',$("#flCode").val());
            }else{
                $("#flCodecomplete").attr('value',$("#parflCodecomplete").val()+"-"+$("#flCode").val());
            }
        }
    })

    /*分类编码管理-修改-选择分类编码树*/
    function selectDeptTree() {
        var flId = $("#treeId").val();
        var excludeId = $("input[name='flId']").val();
        if(flId > 0) {
            var options = {
                title: '分类编码选择',
                width: "380",
                url: prefix + "/selectFlCodeTree/" + $("#treeId").val() + "/" + excludeId,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        } else {
            $.modal.alertError("父分类编码不能选择");
        }
    }

    function doSubmit(index, layero){
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowLastLevel(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
</script>
</body>
</html>
